package com.example;

import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Schema;

public class Generator {

    public static void main(String[] args) throws Exception {

        int version = 1;
        String defaultPackage = "greenDAO.bean";
        //创建模式对象，指定版本号和自动生成的bean对象的包名
        Schema schema = new Schema(version, defaultPackage);
        //指定自动生成的dao对象的包名,不指定则都DAO类生成在"test.greenDAO.bean"包中
        schema.setDefaultJavaPackageDao("greenDAO.dao");

        //添加实体
        addEntity(schema);

        String outDir = "D:/Project/Mingmingde/app/src/main/java-gen";
        //调用DaoGenerator().generateAll方法自动生成代码到之前创建的java-gen目录下
        new DaoGenerator().generateAll(schema, outDir);
    }

    private static void addEntity(Schema schema) {
        //添加一个实体，则会自动生成实体Entity类
        Entity entity = schema.addEntity("Course");
        //指定表名，如不指定，表名则为 Entity（即实体类名）
        entity.setTableName("course");
        //给实体类中添加属性（即给test表中添加字段）
        entity.addIdProperty().autoincrement();//添加Id,自增长
        entity.addIntProperty("week").notNull();//添加Int类型的week,不能为空
        entity.addStringProperty("teacherId").notNull();//添加String类型的studyId,不能为空
        entity.addStringProperty("classRoom");//添加String类型的classRoom
        entity.addIntProperty("weeklyDay").notNull();//添加Int类型的weeklyDay,不能为空
        entity.addIntProperty("weeklyQuarter").notNull();//添加Int类型的weeklyQuarter,不能为空
        entity.addStringProperty("courseName").notNull();//添加String类型的courseName
        entity.addStringProperty("courseId");//添加String类型的courseId
        entity.addStringProperty("beginEndWeek");//添加String类型的beginEndWeek
        entity.addStringProperty("courseWeeklyId");//添加String类型的beginEndWeek
        entity.addIntProperty("courseLength").notNull();//添加Int类型的courseId
        Entity entity1 = schema.addEntity("StudyWeek");
        entity.setTableName("week");
        entity1.addIdProperty().autoincrement();//添加Id,自增长
        entity1.addIntProperty("week").notNull();//添加String类型的week,不能为空
        entity1.addIntProperty("time").notNull();//添加String类型的week

    }

}
